#!/usr/local/bin/perl #------------------------------------------------- # [BBS for i-mode] ver.0.00.1 # # Copyright (C) Minoru Miyajima # All rights reserved. # e-mail: maina_u@livedoor.com #------------------------------------------------- # # ver.0.00.1 #------------------------------------------------- require "surface.pl"; &init_form; if(!$form{"list_head"}){$form{"list_head"}=0;} if(!$form{"list_max"}){$form{"list_max"}=10;} &lock_open(TXT, "log.dat"); for($cnt=0;$cnt<$form{"list_head"};$cnt+=1){$tem = ;} for($cnt=0;$cnt<$form{"list_max"};$cnt+=1){$txt[$cnt] = ;} $next=; &unlock_close(TXT); ##新規投稿 if($form{"mode"} eq "new"){ &dsp_head("BBS NEW"); &dsp_form("","","","",$form{'list_head'}); } ##書き込み elsif($form{"mode"} eq "up"){ $form{"text"}=~s/\n/
/g; &write_msg("log.dat",$form{'name'},$form{'mail'},$form{'title'},$form{'text'}); &dsp_head("BBS NEW"); print "書き込みが終了しました
"; print "一覧に戻る
"; } ##レス書き elsif($form{"mode"} eq "re"){ &dsp_head("BBS RES"); for($cnt=0;$cnt<$form{"list_max"};$cnt+=1){ @out_txt = split(/,/, $txt[$cnt]); if($out_txt[0] eq $form{"list_no"}){ @out_temp = @out_txt; } } $out_temp[11]=~s/
/\n>/g; $out_temp[11]=">".$out_temp[11]; &dsp_form("","","Re\:$out_temp[10]",$out_temp[11],$form{'list_head'}); } ## 読む elsif($form{"mode"} eq "view"){ &dsp_head("BBS READ"); for($cnt=0;$cnt<$form{"list_max"};$cnt+=1){ @out_txt = split(/,/, $txt[$cnt]); if($out_txt[0] eq $form{"list_no"}){ @out_temp = @out_txt; } } # if(length($out_temp[11])>1000){ # print "\n文章が長すぎて表\示しきれませんので、一部のみ表\示します
"; # $out_temp[11]=substr($out_temp[11],0,500); # } print "$out_temp[0]\:"; if(!$out_temp[4]){print "$out_temp[2]";} else {print "$out_temp[2]";} print "
title $out_temp[10]
"; print "$out_temp[11]

"; print "レスを書く
"; print "一覧に戻る
"; } ## 一覧 else { &dsp_head("BBS LIST"); &dsp_list; } &dsp_foot; exit; sub dsp_head{ local($title)=@_; print "Content-type: text/html\nContent-length: 2000\n\n"; print "$title"; } sub dsp_foot{ # local($title)=@_; print '
(c)MYPIXEL
'; } sub dsp_list{ print "[書き込みリスト]
"; print "新しく書き込む
"; if($next){ print "次のページへ
"; } if($form{"list_head"}>0){ print "前のページへ
"; } print "
"; for($cnt=0;$cnt<$form{"list_max"};$cnt+=1){ @out_txt = split(/,/, $txt[$cnt]); if($out_txt[0] != ""){ print "$out_txt[0]\:"; if(!$out_txt[4]){print "$out_txt[2]";} else {print "$out_txt[2]";} print "
title $out_txt[10]
"; } } if($next){ print "次のページへ
"; } if($form{"list_head"}>0){ print "前のページへ"; } } sub dsp_form{ local($name,$mail,$title,$text,$list_head) = @_; print "
"; print ""; print "name:

"; print "mail:

"; print "title:

"; print "message:

"; print "
"; print "
"; print "
"; print "一覧に戻る
"; } sub reload{ local($cginame) = @_; print "Location: $cginame\n\n"; } ########################## ##記事を書き込み## #書き込みデータフォーマット #"$no,$id,$usr_name,$usr_pass,$usr_mail,$usr_url,$usr_d1,$usr_d2,$usr_d3,$usr_date,$usr_sub,$usr_msg\n" ########################## sub write_msg { local($txtfile,$name, $mail, $title, $msg)=@_; local($i,$txt_temp); &lock_open(TXT, "+<$txtfile"); local(@txt)=; seek(TXT,0,0); # 多重書き込み排除 ----------------------------- local($old_no, $old_id, $old_name, $old_pass, $old_mail, $old_url, $old_d1, $old_d2, $old_d3, $old_date, $old_sub, $old_msg) = split(/,/, $txt[0]); chomp($old_msg); chomp($msg); if ($old_msg eq $msg) { &unlock_close(TXT); &dsp_head("BBS LIST"); &dsp_list; } $no = $old_no + 1; $id = 'P'; $date = &get_date; $line = "$no,$id,$name,,$mail,,,,,$date,$title,$msg\n"; unshift(@txt, $line); splice(@txt, $maxarticle); print TXT @txt; truncate(TXT, tell(TXT)); &unlock_close(TXT); } # OPEN & LOCK ---------------------------------------------------------------------------------------------- sub lock_open { local(*FILE, $name) = @_; if (!open(FILE, $name)) { &print_error("$nameがオープンできません。"); } eval("flock(FILE, 2)"); seek(FILE, 0, 0); } # UNLOCK & CLOSE ------------------------------------------------------------------------------------------- sub unlock_close { local(*FILE) = @_; eval("flock(FILE, 8)"); close(FILE); } # INIT FORM ------------------------------------------------------------------------------------------- sub init_form{ require "jcode.pl"; $method = $ENV{'REQUEST_METHOD'}; $method =~ tr/A-Z/a-z/; if ($method eq 'post') { read(STDIN, $query, $ENV{'CONTENT_LENGTH'}); } else { $query = $ENV{'QUERY_STRING'}; } @assocarray = split(/&/, $query); foreach $assoc (@assocarray) { ($property, $value) = split(/=/, $assoc); $value =~ tr/+/ /; $value =~ s/%([A-Fa-f0-9][A-Fa-f0-9])/pack("C", hex($1))/eg; &jcode'convert(*value, 'sjis'); $form{$property} = $value; } } sub get_date { local(@week) = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); local($sec, $min, $hour, $day, $mon, $year, $weekday) = localtime(time); $year += 1900; $mon++; if ($hour < 10) { $hour = "0$hour"; } if ($min < 10) { $min = "0$min"; } if ($sec < 10) { $sec = "0$sec"; } $weekstr = $week[$weekday]; return "$year:$mon:$day:$weekstr:$hour:$min"; }